HackerRank Sam and substrings
提出
11/13 test cases failed :(
code: python
import math
import os
import random
import re
import sys
#
# Complete the 'substrings' function below.
#
# The function is expected to return an INTEGER.
# The function accepts STRING n as parameter.
#
def substrings(n):
# Write your code here
ans = 0
for i in range(1, len(n)+1):
for j in range(len(n)+1 - i):
return ans
if __name__ == '__main__':
n = input()
result = substrings(n)
fptr.write(str(result) + '\n')
fptr.close()
解答
code: python
import math
import os
import random
import re
import sys
#
# Complete the 'substrings' function below.
#
# The function is expected to return an INTEGER.
# The function accepts STRING n as parameter.
#
def substrings(s):
# Write your code here
MOD = 1000000007
n = len(s)
for i in range(1, n):
ans = 0
for i in range(n):
ans += (int(si) * bn-i-1 * (i+1)) % MOD # 1 * 11 * 1 + 6 * 1 * 2
# print(ans) 16 -> 11, 23
ans %= MOD
return ans
if __name__ == '__main__':
n = input()
result = substrings(n)
fptr.write(str(result) + '\n')
fptr.close()
メモ
https://www.youtube.com/watch?v=kXS66eP0T6s
https://scrapbox.io/files/61d24a828b5049001df7341f.png